#ifndef MOTOR_H
#define MOTOR_H

#include <stdint.h>

#define AIN_L_1 PB13
#define AIN_L_2 PB14
#define PWM_L_PIN PWM_TIM1_PARTIAL, PWM_CH2

#define AIN_R_1 PB15
#define AIN_R_2 PA8
#define PWM_R_PIN PWM_TIM1_PARTIAL, PWM_CH3

#define ENCODE_L ENCODE_TIM5
#define ENCODE_R ENCODE_TIM4

#define MOTOR_MAX_OUT 720
#define MOTOR_CTRL_FREQ 10000

#define MOTOR_LIMIT_OUT(out) do {\
    if (out > MOTOR_MAX_OUT) out = MOTOR_MAX_OUT;\
    if (out < -MOTOR_MAX_OUT) out = -MOTOR_MAX_OUT;\
}while(0)

typedef enum {
    MOTOR_LEFT,
    MOTOR_RIGHT,
    MOTOR_ALL,
} MOTOR_SELECT_E;

typedef enum {
    MOTOR_FORWARD,
    MOTOR_BACKWARD,
    MOTOR_FREE_STOP,
    MOTOR_BRAKE,
} MOTOR_STATUS_E;

void MotorInit();
void MotorOut(MOTOR_SELECT_E motor, MOTOR_STATUS_E status, uint32_t out);
int32_t MotorGetSpeedL();
int32_t MotorGetSpeedR();
void MotorTest();

#endif
